import { Table, Space, Card, Button } from 'antd'
import { useStore } from '@/store'
import React, { useEffect, useState } from 'react'
import { useSearchParams } from 'react-router-dom'
import { http } from '@/utils'


const ScoreLine = () => {
    const [varietyData, setVarietyData] = useState({
        list: [],
        count: 0
    })

    const { loginStore } = useStore()
    const [paramsUrl] = useSearchParams()
    const groupRow = {
        key: paramsUrl.get('groupId'),
        label: paramsUrl.get('groupName'),
        value: paramsUrl.get('groupId')
    }
    const [params, setParams] = useState({
        groupId: groupRow.value || '',
        pageNum: 1,
        pageSize: 20
    })
    // // 配置品种预警组
    // let ChildRef = React.createRef()
    // const showModalOpen = (item) => {
    //     ChildRef.current.openConfigModalOpen(item)
    // }

    const pageChange = (page, pageSize) => {
        setVarietyData({ list: [], count: 0 })
        setParams({
            ...params,
            pageSize: pageSize,
            pageNum: page
        })
    }
    useEffect(() => {
        const getList = async () => {
            const res = await http.post('/alarm/deliversign/findFeatureInfoByPage', { userId: loginStore.userId, ...params })
            console.log('品种池列表-', res.body)
            const { list, total } = res.body
            setVarietyData({
                list: list,
                count: total
            })
        }
        getList()
    }, [params, loginStore])
    const columns = [
        { title: '时间', dataIndex: 'id', width: 100, },
        { title: '总分', dataIndex: 'scode', minWidth: 220 },
        { title: '一分', dataIndex: 'displayName', minWidth: 220, },
        { title: '三分', dataIndex: 'sgroupName', minWidth: 220, },
        { title: '五分', dataIndex: 'alarmGroupListText' },
        { title: '刻分', dataIndex: 'alarmGroupListText' },
        { title: '时分', dataIndex: 'alarmGroupListText' },
        { title: '日分', dataIndex: 'alarmGroupListText' },
        { title: '周分', dataIndex: 'alarmGroupListText' },
        { title: '周日分', dataIndex: 'alarmGroupListText' },
        { title: '周日时分', dataIndex: 'alarmGroupListText' },
        { title: '月周日时分', dataIndex: 'alarmGroupListText' },
        {
            title: '操作',
            render: data => {
                return (
                    <Space size="middle">
                        <Button size="small">查看详情</Button>
                    </Space>
                )
            },
            fixed: 'right'
        }
    ]
    return (
        <>
            <Card title="分值趋势">

                <Table
                    style={{ marginTop: 20 }}
                    rowKey="id"
                    size='middle'

                    columns={columns}
                    dataSource={varietyData.list}
                    pagination={
                        {
                            size: 'default',
                            showQuickJumper: true,
                            showSizeChanger: true,
                            pageSize: params.pageSize,
                            total: varietyData.count,
                            onChange: pageChange,
                            current: params.pageNum,
                            showTotal: (total, range) => `共 ${total} 条`,
                        }
                    }
                    bordered
                />
            </Card >
        </>
    )
}

export default ScoreLine